function writetiff(Xguess, name)

[pathstr,~,~]=fileparts(name);
savePath = pathstr;
if exist(savePath)==7,
    ; 
else
    mkdir(savePath); 
end


XguessSAVE1 = uint16(round(0.66*65535*double(Xguess)/double(max(Xguess(:)))));
imwrite(squeeze(XguessSAVE1(:,:,1)), name);
for i = 2:size(XguessSAVE1, 3)
    imwrite(squeeze(XguessSAVE1(:,:,i)), name, 'WriteMode', 'append');
end
end